<?php

class MediaProcessor
{
	static private $_supportedExts = array(
		'photo' => array('jpg', 'jpeg', 'png', 'gif'),
		'video' => array('flv', 'mpg', 'mp1', 'mpeg', 'avi', '3gp', 'wmv', 'mp4', 'ogv'),
		'audio' => array('wma', 'wav', 'mp3', 'aif'),	
	);

	static public function GetMediaTypeByExt($ext)
	{
		 $ext = strtolower(trim($ext, ' .'));
		 foreach (self::$_supportedExts as $type => $exts) 
		 {
		 	if (in_array($ext, $exts)) return $type;
		 }
		 
		 return false;
	}
	
	static public function GetHandler($type, $filePath)
	{
		if (!isset(self::$_supportedExts[$type])) throw new Exception('Неизвестный тип файла');
	
		$classHandlerName = 'MediaHandler' .$type;
		include_once(_APP_PATH. "business/media/media_handler_" .$type. ".php");

		return new $classHandlerName($filePath);
	}
}